package leetcode.二叉树;

import java.util.*;

public class 两树之和输入搜索二叉树653 {
    private List<Integer> list = new ArrayList<>();
    public boolean findTarget(TreeNode root, int k) {
        list.clear();
        process(root);
        Set<Integer> set = new HashSet<>();
        for (Integer integer : list) {
            if (set.contains(integer)) {
                return true;
            }
            set.add(k - integer);
        }
        return false;

    }

    private void process(TreeNode root) {
        if(root == null)
            return;
        process(root.left);
        list.add(root.val);
        process(root.right);
    }
}
